# -*- coding:utf-8 -*-
import sys
from django import forms
from appBlog.models import *

reload(sys)
sys.setdefaultencoding('utf-8')

class SaveModel(models.Model):
	body_text = models.TextField()
	#可添加其它模型字段类型
	def save(self):
		self.body_text = self.body_text.replace("\r\n", "\n")
		self.body_text = self.body_text.replace("\r", "\n")
		super(SaveModel, self).save()

class PoemForm(forms.ModelForm):
	# content = forms.CharField(widget=forms.Textarea,label='内容')

	class Meta:
		model = Poem
		exclude = ('id',)

	def clean(self):
		cleaned_data = super(PoemForm,self).clean()
		value = cleaned_data.get('title')
		try:
			Poem.objects.get(title=value)
			self._errors['title']=self.error_class(['<{}>标题已经存在'.format(value)])
		except Poem.DoesNotExist:
			pass
		return cleaned_data

class ToDoForm(forms.ModelForm):

	class Meta:
		model = ToDo
		fields = ('content','is_done','priority',)


	content = forms.CharField(widget=forms.Textarea,)

class FooForm(forms.Form):
	content = forms.CharField()
	_selected_action = forms.CharField(widget=forms.CharField)


